<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './resize'

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '390px'
      }
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')
        // this.chart.hideLoading()
        this.chart.setOption({
          title: {
            text: '温度（℃）',
            x: 'center'
          },
          tooltip: {

          },
          series: [
            {
              min: 300,
              max: 500,
              name: '温度',
              type: 'gauge',
              detail: null,
              // barWidth: '60%',
              data: [485, 471, 450, 436, 425, 419, 427, 445, 460, 485]
            }
          ]
        })
      }
    }
  }
</script>
